import store from '@/store';
import router from '@/router';
import Vue from 'vue';
import PositionSelector from './PositionSelector';
import TimeSelector from './TimeSelector';
import NumberSelector from './NumberSelector';
import RemarkSelector from './RemarkSelector';
import RewardSelector from './RewardSelector';

function createVM(Origin, opt) {
  const constructor = Vue.extend(Origin);
  return new Promise((resolve, reject) => {
    let params = {
      value: true
    };
    Object.assign(params, opt);
    let vm = new constructor({
      propsData: params,
      store,
      router
    }).$mount();
    if (vm) {
      vm.$on('cancel', () => {
        vm.$destroy();
        reject('关闭');
      });
      vm.$on('submit', data => {
        resolve(data);
        vm.$destroy();
      });
    }
  });
}
const Popup = {
  selectStartPosition() {
    return createVM(PositionSelector, {
      isStart: true
    });
  },
  selectEndPosition() {
    return createVM(PositionSelector, {
      isStart: false
    });
  },
  selectTime(data) {
    return createVM(TimeSelector, data);
  },
  selectNumber(flag) {
    return createVM(NumberSelector, { pinFlag: flag });
  },
  selectRemark(data) {
    return createVM(RemarkSelector, data);
  },
  selectReward() {
    return createVM(RewardSelector);
  }
};
export default Popup;
